//
//  PopupView.m
//  HSBCHybrid
//
//  Created by Marcus on 10/5/14.
//
//

#import "PopupView.h"
#import "PoiItem.h"
#import "Position.h"

@implementation PopupView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor blackColor];
        
//        _showDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        _showDetailButton.frame = self.bounds;
//        [_showDetailButton setTitle:@"showDetail" forState:UIControlStateNormal];
//        [_showDetailButton addTarget:self action:@selector(showDetail) forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:_showDetailButton];
        _typeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 50, 50)];
        _typeImageView.backgroundColor = [UIColor clearColor];
        [self addSubview:_typeImageView];
        
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 10, self.bounds.size.width-110, 40)];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textColor = [UIColor colorWithRed:.96f green:.96f blue:.96f alpha:1];
        _titleLabel.font = [UIFont systemFontOfSize:22];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_titleLabel];
        
  
        
        _tagsLabel = [[UILabel alloc] initWithFrame:CGRectMake(70,  _titleLabel.frame.origin.y+_titleLabel.frame.size.height-10, self.bounds.size.width-110, 40)];
        _tagsLabel.backgroundColor = [UIColor clearColor];
        _tagsLabel.textColor = [UIColor colorWithRed:.96f green:.96f blue:.96f alpha:1];;
        _tagsLabel.font = [UIFont systemFontOfSize:14];
        _tagsLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_tagsLabel];
        
        _distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.bounds.size.width-60,_tagsLabel.frame.origin.y, 50, 44)];
        _distanceLabel.backgroundColor = [UIColor clearColor];
        _distanceLabel.textColor = [UIColor colorWithRed:.96f green:.96f blue:.96f alpha:1];;
        _distanceLabel.font = [UIFont systemFontOfSize:14];
        _distanceLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_distanceLabel];
        
//        _disclosureImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_distanceLabel.frame.origin.x+_distanceLabel.frame.size.width+5, _distanceLabel.frame.origin.y, 30, 30)];
//        _disclosureImageView.backgroundColor = [UIColor clearColor];
//        _disclosureImageView.image = [UIImage imageNamed:@"d-right.png"];
//        [self addSubview:_disclosureImageView];
        
               
    }
    return self;
}

- (void)tapView {
    CGRect theframe = self.frame;
    theframe.origin.y = self.frame.size.height;
    [UIView beginAnimations:@"" context:nil];
    self.frame = theframe;
    [UIView setAnimationDuration:0.3f];
    [UIView commitAnimations];
    
    if (_delegate && [_delegate respondsToSelector:@selector(dismissPopupView)]) {
        [_delegate performSelector:@selector(dismissPopupView)];
    }
}

- (void)setPoiItem:(PoiItem *)poiItem_ {
    _poiItem = poiItem_;
    
//    double distance = [self.locationManager.location distanceFromLocation:coordinate.geoLocation] / 1000;
//    NSString *labelText = [NSString stringWithFormat:@"distance %.2fkm", distance];
//	tempView.distanceLable.text = labelText;
    //Markers get automatically resized
    _titleLabel.text = _poiItem.position.title;
    _tagsLabel.text = _poiItem.position.summary;
    _typeImageView.image = [UIImage imageNamed:_poiItem.position.typeImage];
    _distanceLabel.text = [NSString stringWithFormat:@"%dm",_poiItem.position.demoDistance];
    
}

- (void)setDistance:(double)distance {
   // _distanceLabel.text = [NSString stringWithFormat:@"%f",distance];
}

- (void)showDetail {
    [self tapView];
//    if (_delegate && [_delegate respondsToSelector:@selector(touchPopupView:)]) {
//        [_delegate performSelector:@selector(touchPopupView:) withObject:_poiItem];
//    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
